
package com.x52im.rbchat.logic.alarm.impl;

import android.content.Intent;
import android.provider.Settings;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.x52im.rbchat.R;

import net.x52im.mobileimsdk.android.ClientCoreSDK;

/**
 * 服务器（ 网络）连接失败时的提示包装 实现类.
 *
 * @author Jack Jiang, 2013-12-18
 * @version 2.0
 */
public class NetConnectionFaildHintWrapper {
    /** 父Fragment */
    private Fragment parentFragment = null;
    /** ui组件所属的内容父View对象，对应于Fragment中的getView()对象 */
    private View parentView = null;
    /** 网络连接失败时的提示 */
    private ViewGroup layoutOfNetFaild = null;

    public NetConnectionFaildHintWrapper(Fragment parentFragment, View parentView) {
        this.parentFragment = parentFragment;
        this.parentView = parentView;

        initViews();
        initListeners();
        //
        refreshUI();
    }

    private void initViews() {
        layoutOfNetFaild = parentView.findViewById(R.id.main_alarms_list_netFaildRL);
    }

    private void initListeners() {
        // 直接进入手机中的wifi网络设置界面
        layoutOfNetFaild.setOnClickListener(v -> parentFragment.startActivity(new Intent(Settings.ACTION_SETTINGS)));
    }

    public void refreshUI() {
        if (!ClientCoreSDK.getInstance().isConnectedToServer())
            layoutOfNetFaild.setVisibility(View.VISIBLE);
        else
            layoutOfNetFaild.setVisibility(View.GONE);
    }
}